package com.example.androidpicker;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import android.app.Activity;
import android.app.Dialog;
 
public class MainActivity extends Activity {
Dialog picker;
Button select;
Button set;
TimePicker timep;
DatePicker datep;
Integer hour,minute,month,day,year;
TextView time,date;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        select = (Button)findViewById(R.id.btnSelect);
        time = (TextView)findViewById(R.id.textTime);
        date = (TextView)findViewById(R.id.textDate);
 
        select.setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View view) {
                // TODO Auto-generated method stub
                picker = new Dialog(MainActivity.this);
                picker.setContentView(R.layout.picker_flag);
                picker.setTitle("Select Date and Time");
 
                datep = (DatePicker)picker.findViewById(R.id.datePicker);
                timep = (TimePicker)picker.findViewById(R.id.timePicker1);
                set = (Button)picker.findViewById(R.id.btnSet);
 
                set.setOnClickListener(new View.OnClickListener() {
 
                    @Override
                    public void onClick(View view) {
                        // TODO Auto-generated method stub
                        month = datep.getMonth();
                        day = datep.getDayOfMonth();
                        year = datep.getYear();
                        hour = timep.getCurrentHour();
                        minute = timep.getCurrentMinute();
                        time.setText("Time is "+hour+":" +minute);
                        date.setText("The date is "+day+"/"+month+"/"+year);
                        picker.dismiss();
                    }
                });
                picker.show();
 
            }
        });     
 
    }
}